package znbkTopicType.content;

import android.content.Context;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.lancooznbk.R;

import org.apache.commons.lang3.StringEscapeUtils;

import lancooControl.CustomEditText;
import znbkTestPaperRdqh.activity.WeekAscensionPaperActivity;
import znbkTestPaperXtfx.activity.SystemReviewPaperActivity;
import znbkTopicType.WrapBaseAdapter;
import znbkTestPaperCtfd.activity.WrongTopicTutoringPaperActivity;
import znbkTestPaperInfor.ZnbkPaperDef;

import static znbkTestPaperCtfd.activity.WrongTopicTutoringPaperActivity.mEntityCtfd;
import static znbkTestPaperLstjt.activity.HistoryRecommendQuesPaperActivity.mEntityLstjt;
import static znbkTestPaperNtxl.activity.TrainingDifficultProblemsPaperActivity.mEntityNtxl;
import static znbkTestPaperRdqh.activity.WeekAscensionPaperActivity.mEntityRdqh;
import static znbkTestPaperXtfx.activity.SystemReviewPaperActivity.mEntityXtfx;

/**
 * Created by Administrator on 2018\2\26 0026.
 */

public class ZnbkContentZwAdapter extends WrapBaseAdapter {

    private LayoutInflater mInflater;
    private Context mContext;
    //当前试题数量
    private int ItemCount;
    //当前试题在当前试卷的ID
    private int PaperID;
    private int ModelFrom;//试卷来源

    private int tvBlack;
    private int tvBlue;
    private int tvWhite;
    private int tvGreen;
    private int tvRed;
    private int tvGray;

    private ViewHolder holder = null;
    private class ViewHolder{
        WebView mWvTheme;//大题文本题干区
//        LinearLayout mLayoutEdtAnswer;//作文输入区所在布局
        CustomEditText mEdtAnswer;//作文输入区
        LinearLayout mLayoutCheckAnalysis;//答案回看解析区
        LinearLayout mLayoutStuAnswer;
        LinearLayout mLayoutTvStuAnswer;
        LinearLayout mLayoutAnswer;
        LinearLayout mLayoutTvAnswer;
        LinearLayout mLayoutAnalysis;
        LinearLayout mLayoutStuAssess;
        RadioGroup mRgAssess;
        RadioButton mRBtnExcellent;
        RadioButton mRBtnGood;
        RadioButton mRBtnQualified;
        RadioButton mRBtnRange;
        TextView mTvStuAssess;//自评
        TextView mTvAnalysis;//解析

        private ViewHolder(View convertView) {

            mWvTheme = (WebView) convertView.findViewById(R.id.wv_theme);
//            mLayoutEdtAnswer = (LinearLayout) convertView.findViewById(R.id.layout_edtAnswer);
            mEdtAnswer = (CustomEditText) convertView.findViewById(R.id.edt_answer);
            mLayoutCheckAnalysis = (LinearLayout) convertView.findViewById(R.id.layout_checkAnalysis);
            mLayoutStuAnswer = (LinearLayout) convertView.findViewById(R.id.layout_stuAnswer);
            mLayoutTvStuAnswer = (LinearLayout) convertView.findViewById(R.id.layout_tvStuAnswer);
            mLayoutAnswer = (LinearLayout) convertView.findViewById(R.id.layout_answer);
            mLayoutTvAnswer = (LinearLayout) convertView.findViewById(R.id.layout_tvAnswer);
            mLayoutStuAssess = (LinearLayout) convertView.findViewById(R.id.layout_stuAssess);
            mLayoutAnalysis = (LinearLayout) convertView.findViewById(R.id.layout_analysis);
            mRgAssess = (RadioGroup) convertView.findViewById(R.id.rg_assess);
            mRBtnExcellent = (RadioButton) convertView.findViewById(R.id.rbtn_excellent);
            mRBtnGood = (RadioButton) convertView.findViewById(R.id.rbtn_good);
            mRBtnQualified = (RadioButton) convertView.findViewById(R.id.rbtn_qualified);
            mRBtnRange = (RadioButton) convertView.findViewById(R.id.rbtn_range);
            mTvStuAssess = (TextView) convertView.findViewById(R.id.tv_stuAssess);
            mTvAnalysis = (TextView) convertView.findViewById(R.id.tv_analysis);
        }
    }

    /*
   * 获取小题选项信息
   * */
    private String theme;//大题题干
    private String quesImage = "";//作文大题题干图片信息
    private int status;//试卷的作答状态
    private String stuAssess;//自评/机评结果
    private String stuAnswer;//用户答案
    private String answer;//正确答案
    private double score;//试题总分值
    private String analysis;//答案解析
    private Double correctRate;//该题准确率
    private String typeName;

    public ZnbkContentZwAdapter(Context context, int itemCount, int paperID, int modelFrom) {
        mInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.ItemCount = itemCount;
        this.PaperID = paperID;
        this.ModelFrom = modelFrom;
    }

    @Override
    public int getCount() {
        return ItemCount;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.znbk_adapter_content_zw_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        /*
        * 获取作文题用户相关信息
        * */
        getQuesInfor();

        /*
        * 显示题干信息
        * */
        showQuesInfor();

        /*
        * 显示用户回看解析相关信息
        */
        showAnalysis();

        return convertView;
    }


    /*
    * 获取作文题用户相关信息
    * */
    private void  getQuesInfor(){

        tvBlack = mContext.getResources().getColor(R.color.black);
        tvBlue = mContext.getResources().getColor(R.color.blue);
        tvWhite = mContext.getResources().getColor(R.color.white);
        tvGreen = mContext.getResources().getColor(R.color.green);
        tvRed = mContext.getResources().getColor(R.color.red);
        tvGray = mContext.getResources().getColor(R.color.gray);

        if(ModelFrom== ZnbkPaperDef.FROM_SYSTEM_REVIEW) {
            theme = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
            status = mEntityXtfx.getModelSinglePaperInfo().getModelPaperInfo().getAnswerState();
            score = mEntityXtfx.getModelSinglePaperInfo().getModelPaperInfo().getDetail().get(PaperID).getScore();
            answer = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
            analysis = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
            stuAssess = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
            typeName = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getTypeName();
            //用户答案
            stuAnswer = mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
            if(status==3) {
                correctRate = mEntityXtfx.getModelItemAnswerDetailList().get(PaperID).getCorrectRate();
            }else{
                correctRate = 0.0;
            }
        }else if(ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
            theme = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
            status = mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().getAnswerState();
            score = mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().getDetail().get(PaperID).getScore();
            answer = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
            analysis = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
            stuAssess = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
            typeName = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getTypeName();
            //用户答案
            stuAnswer = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
            if(status==3) {
                correctRate = mEntityRdqh.getModelItemAnswerDetailList().get(PaperID).getCorrectRate();
            }else{
                correctRate = 0.0;
            }
        }else if(ModelFrom==ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS){
            theme = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
            stuAnswer = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
            status = mEntityNtxl.getAnswerState();
            answer = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
            analysis = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
            stuAssess = mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
            typeName = mEntityNtxl.getTKQue().getTypeName();
            correctRate = mEntityNtxl.getCorrectRate();
        }else if(ModelFrom==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING){

            int anotherPaperID = -1;
            if (PaperID == 0) {
                status = 3;
                //获取小题题干内容
                theme = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
                //用户答案
                stuAnswer = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
                //正确答案
                answer = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
                //自评结果
                stuAssess = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
                //答案解析
                analysis = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
                //题型
                typeName = mEntityCtfd.getPrimitiveQues().getTKQue().getTypeName();
            } else {

                if(PaperID==1){
                    anotherPaperID = PaperID-1;
                    if (mEntityCtfd.getClassicalQues()!= null) {
                        status = 3;
                        //获取小题题干内容
                        theme = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
                        //用户答案
                        stuAnswer = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
                        //正确答案
                        answer = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
                        //自评结果
                        stuAssess = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
                        //答案解析
                        analysis = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
                        //题型
                        typeName = mEntityCtfd.getClassicalQues().getTKQue().getTypeName();
                    }else{
                        //试卷的作答状态
                        status = mEntityCtfd.getRecQues().get(anotherPaperID).getAnswerState();
                        //获取小题题干内容
                        theme = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
                        //用户答案
                        stuAnswer = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
                        //正确答案
                        answer = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
                        //自评结果
                        stuAssess = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
                        //答案解析
                        analysis = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
                        //题型
                        typeName = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getTypeName();
                    }
                }else{
                    if (mEntityCtfd.getClassicalQues()!= null) {
                        anotherPaperID = PaperID - 2;
                    } else {
                        anotherPaperID = PaperID - 1;
                    }
                    //试卷的作答状态
                    status = mEntityCtfd.getRecQues().get(anotherPaperID).getAnswerState();
                    //获取小题题干内容
                    theme = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
                    //用户答案
                    stuAnswer = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
                    //正确答案
                    answer = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
                    //自评结果
                    stuAssess = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
                    //答案解析
                    analysis = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
                    //题型
                    typeName = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getTypeName();
                }
            }
        }else if(ModelFrom==ZnbkPaperDef.FROM_HISTORY_RECOMMEND_QUESTION){
            theme = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
            status = 3;
            answer = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
            analysis = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnalyze();
            stuAssess = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
            typeName = mEntityLstjt.get(PaperID).getTKQue().getTypeName();
            //用户答案
            stuAnswer = mEntityLstjt.get(PaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
            if(status==3) {
                correctRate = mEntityLstjt.get(PaperID).getCorrectRate();
            }else{
                correctRate = 0.0;
            }
        }

    }

    /*
    * 显示界面信息
    * */
    private void showQuesInfor(){
        if(status==2||status==3){
            holder.mEdtAnswer.setVisibility(View.GONE);
        }else{
            holder.mEdtAnswer.setVisibility(View.VISIBLE);
            if(stuAnswer.equals("")){
                holder.mEdtAnswer.setHint("在此输入答案，提交后请自评");
            }else{
                holder.mEdtAnswer.setText(stuAnswer);
            }

            /*
            * 用户输入框作答
            * */
            edtStuAnswer();
        }
        getTheme();
    }

    private void getTheme(){
        theme = theme.replaceAll("______","_");
        theme = StringEscapeUtils.unescapeXml(theme);
        holder.mWvTheme.loadDataWithBaseURL("about:blank",theme,"text/html","utf-8",null);
        holder.mWvTheme.getSettings().setDefaultFontSize(18);
        holder.mWvTheme.setFocusable(false);
        holder.mWvTheme.getSettings().setJavaScriptEnabled(true);
    }


    /*
    * 用户作答
    * */
    private void edtStuAnswer(){

        holder.mEdtAnswer.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                setStuAnswer(s.toString());
            }
        });
    }

    /*
    * 显示试题解析回看信息
    * */
    private void showAnalysis(){


            if(ModelFrom == ZnbkPaperDef.FROM_SYSTEM_REVIEW||
                    ModelFrom == ZnbkPaperDef.FROM_WEEK_ASCENSION||
                    ModelFrom == ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS||
                    ModelFrom==ZnbkPaperDef.FROM_HISTORY_RECOMMEND_QUESTION) {

                if(status==0||status==1){
                    /*
                    * 隐藏提交回看界面
                    * */
                    holder.mLayoutCheckAnalysis.setVisibility(View.GONE);

                }else if(status==2||status==3){
                     /*
                * 显示提交回看界面
                * */
                    holder.mLayoutCheckAnalysis.setVisibility(View.VISIBLE);
                    /*
                    * 显示我的答案
                    * */
                    holder.mLayoutStuAnswer.setVisibility(View.VISIBLE);
                    TextView mTvStuAnswer = new TextView(mContext);
                    if(stuAnswer.equals("")){
                        mTvStuAnswer.setText(R.string.znbk_no_answered);
                    }else{
                        mTvStuAnswer.setText(stuAnswer);
                    }
                    if(stuAnswer.equals(answer)) {
                        mTvStuAnswer.setTextColor(tvGreen);
                    }else{
                        mTvStuAnswer.setTextColor(tvRed);
                    }
                    holder.mLayoutTvStuAnswer.addView(mTvStuAnswer);

                    /*
                    * 显示参考答案
                    * */
                    TextView mTvAnswer = new TextView(mContext);
                    mTvAnswer.setText(Html.fromHtml(answer));
                    mTvAnswer.setTextColor(tvGreen);
                    holder.mLayoutTvAnswer.addView(mTvAnswer);


                /*
                * 显示自评区
                * */
                    holder.mLayoutStuAssess.setVisibility(View.VISIBLE);

                    if(status==2){
                        /*
                        * 显示自评选项
                        * 隐藏自评结果
                        * */
                        holder.mRgAssess.setVisibility(View.VISIBLE);
                        holder.mRBtnExcellent.setChecked(false);
                        holder.mRBtnGood.setChecked(false);
                        holder.mRBtnQualified.setChecked(false);
                        holder.mRBtnRange.setChecked(false);
                        if(stuAssess.equals("优秀")){
                            holder.mRBtnExcellent.setChecked(true);
                        }else  if(stuAssess.equals("良好")){
                            holder.mRBtnGood.setChecked(true);
                        }else  if(stuAssess.equals("合格")){
                            holder.mRBtnQualified.setChecked(true);
                        }else  if(stuAssess.equals("较差")){
                            holder.mRBtnRange.setChecked(true);
                        }
                        holder.mRgAssess.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                            @Override
                            public void onCheckedChanged(RadioGroup group, int checkedId) {
                                if(checkedId==holder.mRBtnExcellent.getId()){
                                    stuAssess = "优秀";
                                }else if(checkedId==holder.mRBtnGood.getId()){
                                    stuAssess = "良好";
                                }else if(checkedId==holder.mRBtnQualified.getId()){
                                    stuAssess = "合格";
                                }else if(checkedId==holder.mRBtnRange.getId()){
                                    stuAssess = "较差";
                                }
                                if(ModelFrom == ZnbkPaperDef.FROM_SYSTEM_REVIEW){
                                    mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).setSubChildStuAssess(stuAssess);
                                }else if(ModelFrom == ZnbkPaperDef.FROM_WEEK_ASCENSION){
                                    mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).setSubChildStuAssess(stuAssess);
                                }else if(ModelFrom == ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS) {
                                    mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).setSubChildStuAssess(stuAssess);
                                }
                            }
                        });
                        holder.mTvStuAssess.setVisibility(View.GONE);

                    } else if(status==3){
                         /*
                        * 隐藏自评选项
                        * 显示自评结果
                        * */
                        holder.mRgAssess.setVisibility(View.GONE);

                        holder.mTvStuAssess.setVisibility(View.VISIBLE);
                        if (stuAssess.equals("")) {
                            holder.mTvStuAssess.setText(R.string.znbk_no_assessed);
                        } else {
                            holder.mTvStuAssess.setText(stuAssess);
                        }
                        holder.mTvStuAssess.setTextColor(tvBlue);
                    }


                /*
                * 显示答案解析
                * */
                    if(status==2){
                        holder.mLayoutAnalysis.setVisibility(View.GONE);
                    } else if(status==3) {

                        holder.mLayoutAnalysis.setVisibility(View.VISIBLE);

                        if (analysis.equals("")) {
                            holder.mTvAnalysis.setText(R.string.znbk_no_analysis);
                        } else {
                            holder.mTvAnalysis.setText(Html.fromHtml(analysis));
                        }
                        holder.mTvAnalysis.setTextColor(tvBlack);

                    }
                }

        }
        /*
        * 错题辅导
        * */
        if (ModelFrom == ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING) {
            if (PaperID == 0) {
                //显示题目回看解析内容
                holder.mLayoutCheckAnalysis.setVisibility(View.VISIBLE);

                /*
                * 显示我的答案
                * */
                holder.mLayoutStuAnswer.setVisibility(View.VISIBLE);
                TextView mTvStuAnswer = new TextView(mContext);
                if(stuAnswer.equals("")){
                    mTvStuAnswer.setText(R.string.znbk_no_answered);
                }else{
                    mTvStuAnswer.setText(stuAnswer);
                }
                if(stuAnswer.equals(answer)) {
                    mTvStuAnswer.setTextColor(tvGreen);
                }else{
                    mTvStuAnswer.setTextColor(tvRed);
                }
                holder.mLayoutTvStuAnswer.addView(mTvStuAnswer);

                /*
                * 显示参考答案
                * */
                holder.mLayoutTvAnswer.setVisibility(View.VISIBLE);
                TextView mTvAnswer = new TextView(mContext);
                mTvAnswer.setText(Html.fromHtml(answer));
                mTvAnswer.setTextColor(tvGreen);
                holder.mLayoutTvAnswer.addView(mTvAnswer);

                /*
                *  隐藏自评选项
                *  显示自评结果
                * */
                holder.mRgAssess.setVisibility(View.GONE);
                holder.mLayoutStuAssess.setVisibility(View.VISIBLE);
                if(!stuAssess.equals("")) {
                    holder.mTvStuAssess.setText(stuAssess);
                }else{
                    holder.mTvStuAssess.setText(R.string.znbk_no_assessed);
                }
                //答案解析
                if (!analysis.equals("")) {
                    holder.mTvAnalysis.setText(Html.fromHtml(analysis));
                } else {
                    holder.mTvAnalysis.setText(R.string.znbk_no_analysis);
                }
                holder.mTvAnalysis.setTextColor(tvBlack);

            } else if (PaperID == 1) {

                if (mEntityCtfd.getClassicalQues() != null) {

                    //显示题目回看解析内容
                    holder.mLayoutCheckAnalysis.setVisibility(View.VISIBLE);

                    /*
                    * 隐藏我的答案
                    * */
                    holder.mLayoutStuAnswer.setVisibility(View.GONE);

                    //显示参考答案
                    holder.mLayoutAnswer.setVisibility(View.VISIBLE);
                    TextView mTvAnswer = new TextView(mContext);
                    mTvAnswer.setText(Html.fromHtml(answer));
                    mTvAnswer.setTextColor(tvGreen);
                    holder.mLayoutTvAnswer.addView(mTvAnswer);

                    //隐藏自评结果
                    holder.mLayoutStuAssess.setVisibility(View.GONE);
                    //显示答案解析
                    if (!analysis.equals("")) {
                        holder.mTvAnalysis.setText(Html.fromHtml(analysis));
                    } else {
                        holder.mTvAnalysis.setText(R.string.znbk_no_analysis);
                    }

                } else {
                    if(status==0||status==1){
                        //隐藏题目回看解析内容
                        holder.mLayoutCheckAnalysis.setVisibility(View.GONE);
                    }
                    else if (status == 2 || status == 3) {

                        //显示题目回看解析内容
                        holder.mLayoutCheckAnalysis.setVisibility(View.VISIBLE);

                        /*
                        * 显示我的答案
                        * */
                        holder.mLayoutStuAnswer.setVisibility(View.VISIBLE);
                        TextView mTvStuAnswer = new TextView(mContext);

                        if (stuAnswer.equals("")) {
                            mTvStuAnswer.setText(R.string.znbk_no_answered);
                        } else {
                            mTvStuAnswer.setText(stuAnswer);
                        }

                        if(status==2){
                            mTvStuAnswer.setTextColor(tvBlue);
                        }else if(status==3){
                            if (stuAnswer.equals(answer)) {
                                mTvStuAnswer.setTextColor(tvGreen);
                            } else {
                                mTvStuAnswer.setTextColor(tvRed);
                            }
                        }

                        holder.mLayoutTvStuAnswer.addView(mTvStuAnswer);

                        //显示参考答案
                        holder.mLayoutAnswer.setVisibility(View.VISIBLE);
                        TextView mTvAnswer = new TextView(mContext);
                        mTvAnswer.setText(Html.fromHtml(answer));
                        mTvAnswer.setTextColor(tvGreen);
                        holder.mLayoutTvAnswer.addView(mTvAnswer);


                       /*
                        * 显示自评区
                        * */
                        holder.mLayoutStuAssess.setVisibility(View.VISIBLE);

                        if (status == 2) {
                            /*
                            * 显示自评选项
                            * 隐藏自评结果
                            * */
                            holder.mRgAssess.setVisibility(View.VISIBLE);
                            holder.mRBtnExcellent.setChecked(false);
                            holder.mRBtnGood.setChecked(false);
                            holder.mRBtnQualified.setChecked(false);
                            holder.mRBtnRange.setChecked(false);
                            if (stuAssess.equals("优秀")) {
                                holder.mRBtnExcellent.setChecked(true);
                            } else if (stuAssess.equals("良好")) {
                                holder.mRBtnGood.setChecked(true);
                            } else if (stuAssess.equals("合格")) {
                                holder.mRBtnQualified.setChecked(true);
                            } else if (stuAssess.equals("较差")) {
                                holder.mRBtnRange.setChecked(true);
                            }
                            holder.mRgAssess.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                                @Override
                                public void onCheckedChanged(RadioGroup group, int checkedId) {
                                    if (checkedId == holder.mRBtnExcellent.getId()) {
                                        stuAssess = "优秀";
                                    } else if (checkedId == holder.mRBtnGood.getId()) {
                                        stuAssess = "良好";
                                    } else if (checkedId == holder.mRBtnQualified.getId()) {
                                        stuAssess = "合格";
                                    } else if (checkedId == holder.mRBtnRange.getId()) {
                                        stuAssess = "较差";
                                    }
                                    int anotherPaperID = -1;
                                    if(mEntityCtfd.getClassicalQues()!=null){
                                        anotherPaperID = PaperID-2;
                                    }else{
                                        anotherPaperID = PaperID-1;
                                    }
                                    mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).setSubChildStuAssess(stuAssess);
                                }
                            });
                            holder.mTvStuAssess.setVisibility(View.GONE);

                            /*
                            * 隐藏答案解析
                            * */
                            holder.mLayoutAnalysis.setVisibility(View.GONE);

                        } else if (status == 3) {
                         /*
                        * 隐藏自评选项
                        * 显示自评结果
                        * */
                            holder.mRgAssess.setVisibility(View.GONE);

                            holder.mTvStuAssess.setVisibility(View.VISIBLE);
                            if (stuAssess.equals("")) {
                                holder.mTvStuAssess.setText(R.string.znbk_no_assessed);
                            } else {
                                holder.mTvStuAssess.setText(stuAssess);
                            }

                            /*
                            * 显示答案解析
                            * */
                            holder.mLayoutAnalysis.setVisibility(View.VISIBLE);
                            if (!analysis.equals("")) {
                                holder.mTvAnalysis.setText(Html.fromHtml(analysis));
                            } else {
                                holder.mTvAnalysis.setText(R.string.znbk_no_analysis);
                            }
                            holder.mTvAnalysis.setTextColor(tvBlack);

                        } else {

                            //关闭题目回看解析内容
                            holder.mLayoutCheckAnalysis.setVisibility(View.GONE);
                        }
                    }
                }
            }else {
                if(status==0||status==1){
                    //隐藏题目回看解析内容
                    holder.mLayoutCheckAnalysis.setVisibility(View.GONE);
                }
                else if (status == 2 || status == 3) {

                    //显示题目回看解析内容
                    holder.mLayoutCheckAnalysis.setVisibility(View.VISIBLE);

                    /*
                    * 显示我的答案
                    * */
                    holder.mLayoutStuAnswer.setVisibility(View.VISIBLE);
                    TextView mTvStuAnswer = new TextView(mContext);
                    if (stuAnswer.equals("")) {
                        mTvStuAnswer.setText(R.string.znbk_no_answered);
                    } else {
                        mTvStuAnswer.setText(stuAnswer);
                    }
                    if(status==2){
                        mTvStuAnswer.setTextColor(tvBlue);
                    }else if(status==3){
                        if (stuAnswer.equals(answer)) {
                            mTvStuAnswer.setTextColor(tvGreen);
                        } else {
                            mTvStuAnswer.setTextColor(tvRed);
                        }
                    }
                    holder.mLayoutTvStuAnswer.addView(mTvStuAnswer);

                    /*
                    * 显示参考答案
                    * */
                    holder.mLayoutAnswer.setVisibility(View.VISIBLE);
                    TextView mTvAnswer = new TextView(mContext);
                    mTvAnswer.setText(Html.fromHtml(answer));
                    mTvAnswer.setTextColor(tvGreen);
                    holder.mLayoutTvAnswer.addView(mTvAnswer);


                    /*
                    * 显示自评区
                    * */
                    holder.mLayoutStuAssess.setVisibility(View.VISIBLE);

                    if (status == 2) {
                        /*
                        * 显示自评选项
                        * 隐藏自评结果
                        * */
                        holder.mRgAssess.setVisibility(View.VISIBLE);
                        holder.mRBtnExcellent.setChecked(false);
                        holder.mRBtnGood.setChecked(false);
                        holder.mRBtnQualified.setChecked(false);
                        holder.mRBtnRange.setChecked(false);
                        if (stuAssess.equals("优秀")) {
                            holder.mRBtnExcellent.setChecked(true);
                        } else if (stuAssess.equals("良好")) {
                            holder.mRBtnGood.setChecked(true);
                        } else if (stuAssess.equals("合格")) {
                            holder.mRBtnQualified.setChecked(true);
                        } else if (stuAssess.equals("较差")) {
                            holder.mRBtnRange.setChecked(true);
                        }
                        holder.mRgAssess.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                            @Override
                            public void onCheckedChanged(RadioGroup group, int checkedId) {
                                if (checkedId == holder.mRBtnExcellent.getId()) {
                                    stuAssess = "优秀";
                                } else if (checkedId == holder.mRBtnGood.getId()) {
                                    stuAssess = "良好";
                                } else if (checkedId == holder.mRBtnQualified.getId()) {
                                    stuAssess = "合格";
                                } else if (checkedId == holder.mRBtnRange.getId()) {
                                    stuAssess = "较差";
                                }
                                int anotherPaperID = -1;
                                if(mEntityCtfd.getClassicalQues()!=null){
                                    anotherPaperID = PaperID-2;
                                }else{
                                    anotherPaperID = PaperID-1;
                                }
                                mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).setSubChildStuAssess(stuAssess);
                            }
                        });
                        holder.mTvStuAssess.setVisibility(View.GONE);

                        /*
                        * 隐藏答案解析
                        * */
                        holder.mLayoutAnalysis.setVisibility(View.GONE);

                    } else if (status == 3) {
                         /*
                        * 隐藏自评选项
                        * 显示自评结果
                        * */
                        holder.mRgAssess.setVisibility(View.GONE);

                        holder.mTvStuAssess.setVisibility(View.VISIBLE);
                        if (stuAssess.equals("")) {
                            holder.mTvStuAssess.setText(R.string.znbk_no_assessed);
                        } else {
                            holder.mTvStuAssess.setText(stuAssess);
                        }


                        /*
                        * 显示答案解析
                        * */
                        holder.mLayoutAnalysis.setVisibility(View.VISIBLE);
                        if (!analysis.equals("")) {
                            holder.mTvAnalysis.setText(Html.fromHtml(analysis));
                        } else {
                            holder.mTvAnalysis.setText(R.string.znbk_no_analysis);
                        }
                        holder.mTvAnalysis.setTextColor(tvBlack);


                    } else {

                        //关闭题目回看解析内容
                        holder.mLayoutCheckAnalysis.setVisibility(View.GONE);
                    }
                }
            }
        }


    }

    /*
  * 写入作答信息
  * */
    private void setStuAnswer(String strStuAnswer){

         if(ModelFrom== ZnbkPaperDef.FROM_TRAINING_DIFFICULT_PROBLEMS){
             mEntityNtxl.getTKQue().getChildList().get(0).getSubChildList().get(0).setSubChildStuAnswer(strStuAnswer);
             if(strStuAnswer.equals("")){
                 mEntityNtxl.setAnswerState(0);
             }else{
                 mEntityCtfd.setAnswerState(1);
             }
         }else if(ModelFrom==ZnbkPaperDef.FROM_SYSTEM_REVIEW){
             mEntityXtfx.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).setSubChildStuAnswer(strStuAnswer);

             int AnswerState = mEntityXtfx.getModelSinglePaperInfo().getModelPaperInfo().getAnswerState();
             if(AnswerState==0){
                 if(!strStuAnswer.equals("")){
                     mEntityXtfx.getModelSinglePaperInfo().getModelPaperInfo().setAnswerState(1);
                 }
                 SystemReviewPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
             }
         }else if(ModelFrom==ZnbkPaperDef.FROM_WEEK_ASCENSION){
             mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().get(PaperID).getChildList().get(0).getSubChildList().get(0).setSubChildStuAnswer(strStuAnswer);

             int AnswerState = mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().getAnswerState();
             if(AnswerState==0){
                 if(!strStuAnswer.equals("")){
                     mEntityRdqh.getModelSinglePaperInfo().getModelPaperInfo().setAnswerState(1);
                 }
                 WeekAscensionPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
             }
         }else if(ModelFrom==ZnbkPaperDef.FROM_WRONG_TOPIC_TUTORING){
             int anotherPaperID = -1;
             if(mEntityCtfd.getClassicalQues()!=null){
                 anotherPaperID = WrongTopicTutoringPaperActivity.currentBigViewPage-2;
             }else{
                 anotherPaperID = WrongTopicTutoringPaperActivity.currentBigViewPage-1;
             }
             if(anotherPaperID>=0){

                 mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().
                         get(0).setSubChildStuAnswer(strStuAnswer);
                 if(strStuAnswer.equals("")){
                     mEntityCtfd.getRecQues().get(anotherPaperID).setAnswerState(0);
                 }else{
                     mEntityCtfd.getRecQues().get(anotherPaperID).setAnswerState(1);
                 }

                 int RecQuesCount = mEntityCtfd.getRecQues().size();
                 boolean IsAnswered = false;
                 for(int i=0;i<RecQuesCount;i++){
                     int RecQuesAnswerState =  mEntityCtfd.getRecQues().get(i).getAnswerState();
                     if(RecQuesAnswerState>0){
                         IsAnswered = true;
                     }
                 }
                 if(IsAnswered){
                     if(mEntityCtfd.getAnswerState()==0){
                         mEntityCtfd.setAnswerState(1);
                     }
                     WrongTopicTutoringPaperActivity.mSbtnSubmit.setTextColor(tvWhite);
                 }else{
                     if(mEntityCtfd.getAnswerState()==1){
                         mEntityCtfd.setAnswerState(0);
                     }
                     WrongTopicTutoringPaperActivity.mSbtnSubmit.setTextColor(tvGray);
                 }

             }

         }
    }
}